package fhp.hlhj.giantfold.adapter

import android.content.Context
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import fhp.hlhj.giantfold.R

/**
 * author: FHP
 * data: on 2018\1\5 0005 15:43
 * E-Mail: 103945089@qq.com
 */
class MyFansListAdp(private var context: Context,private var datas:List<String>) :BaseAdapter(){

    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View? {
        var convertView=convertView
        if (convertView==null){
            convertView=LayoutInflater.from(context).inflate(R.layout.myfans_listitem,null)
        }
        return convertView
    }

    override fun getItem(position: Int): Any = datas[position]

    override fun getItemId(position: Int): Long = position.toLong()

    override fun getCount(): Int =datas.size

    fun <T : View> View.findViewOften(viewId: Int): T {
        var viewHolder: SparseArray<View> = tag as? SparseArray<View> ?: SparseArray()
        tag = viewHolder
        var childView: View? = viewHolder.get(viewId)
        if (null == childView) {
            childView = findViewById(viewId)
            viewHolder.put(viewId, childView)
        }
        return childView as T
    }
}